import { themes } from './model'
import localCache from '@/utils/auth'
const changeStyle = (config) => {
  for (const key in config) {
    document.getElementsByTagName('body')[0].style.setProperty(key, config[key])
  }
}

// 设置选中主题
export const setTheme = (themeName) => {
  localCache.setCache(localCache.THEME_KET, themeName)
  const themeConfig = themes[themeName]
  if (themeConfig) {
    changeStyle(themeConfig)
  } else {
    // 如果选中不存在主题，选中默认主题
    changeStyle(themes['light'])
  }
}
